using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyPath_CSharp
{
    class EnvironmentUtils
    {
        /**
         * 遍历环境变量
         */
        public static Dictionary<string, string> list()
        {

            var keyValue = new Dictionary<string, string>();

            foreach (DictionaryEntry de in Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine))
            {
                keyValue.Add(de.Key.ToString(), de.Value.ToString());

                // Console.WriteLine("key: {0},value: {1}", de.Key.ToString(), de.Value.ToString());
            }

            return keyValue;
        }

        /**
         * 设置环境变量
         */
        public static void set(IDictionary<string, string> keyValue)
        {
            foreach (KeyValuePair<string, string> kvp in keyValue)
            {
                Console.WriteLine($"key: {kvp.Key},value: {kvp.Value}");
                Environment.SetEnvironmentVariable(kvp.Key, kvp.Value, EnvironmentVariableTarget.Machine);
            }
        }

        /**
         * 删除环境变量
         */
        public static void remove(List<string> keys)
        {
           

            foreach (String key in keys)
            {
                Console.WriteLine($"delete key: {key}");
                Environment.SetEnvironmentVariable(key, null, EnvironmentVariableTarget.Machine);
            }
        }
    }
}
